package com.centaline.androidsalesblog.rx.request;

import com.android.volley.VolleyError;
import com.centaline.androidsalesblog.api.sale.PersonalizeApi;
import com.centaline.androidsalesblog.model.responseobject.PersonalizeRo;
import com.centanet.framework.interfaces.IResponseListener;

import rx.Observable;
import rx.Subscriber;

/**
 * 首页模块
 * Created by guilin on 16/1/21.
 */
final class RequestPersonalizeOnSubscribe implements Observable.OnSubscribe<PersonalizeRo> {

    private final Class<?> tag;

    public RequestPersonalizeOnSubscribe(Class<?> tag) {
        this.tag = tag;
    }

    @Override
    public void call(final Subscriber<? super PersonalizeRo> subscriber) {
        new PersonalizeApi(tag, PersonalizeRo.class, new IResponseListener<PersonalizeRo>() {
            @Override
            public void onResponse(PersonalizeRo personalizeRo) {
                if (!subscriber.isUnsubscribed()) {
                    subscriber.onNext(personalizeRo);
                }
                subscriber.onCompleted();
            }

            @Override
            public void onErrorResponse(VolleyError error) {
                subscriber.onError(error);
            }
        }).startRequest();
    }
}
